﻿
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace SarsClient.GUI
{
	/// <summary>
	/// User control for IP entry.
	/// </summary>
	public partial class IPTextBox : UserControl
	{
		public IPTextBox()
		{
			InitializeComponent();
		}
		
		/// <summary>
		/// Get: Returns the input IP.
		/// Set: Sets text to IP.
		/// </summary>
		/// <returns 
		public System.Net.IPAddress IPAddress {
			get {
				System.Net.IPAddress ret = null;
				try {
					ret = System.Net.IPAddress.Parse(String.Format("{0}.{1}.{2}.{3}",this.tbIp1.Text, this.tbIp2.Text, this.tbIp3.Text, this.tbIp4.Text));
				} catch {
					
				}
				return ret;
			}
			set {
				String[] parts = value.ToString().Split(".".ToCharArray());
				this.tbIp1.Text = parts[0];
				this.tbIp2.Text = parts[1];
				this.tbIp3.Text = parts[2];
				this.tbIp4.Text = parts[3];
			}
		}

		
		// called when text in any TextBox is changed
		void IpTextChanged(object sender, EventArgs e)
		{
			//TextChanged(sender,e);
			this.OnTextChanged(e);
		}
		
		void TbIp1KeyPress(object sender, KeyPressEventArgs e)
		{
			this.OnKeyPress(e);
		}
	}
}
